<!-- 审批列表 -->
<template>
  <div class="app-container">
    <searchForm
      :formOptions="formOptions"
      @onSearch="onSearch"
      @onReset="onReset"
      :formLabelWidth="formLabelWidth"
      v-show="showSearch"
    />
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table :data="applyList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="学号"
        prop="roleName"
        :show-overflow-tooltip="true"
        align="center"
      />
      <el-table-column label="申请人" prop="roleKey" align="center" />
      <el-table-column label="所在院部" prop="roleSort" align="center" />
      <el-table-column label="专业" prop="roleSort" align="center" />
      <el-table-column label="班级" prop="roleSort" align="center" />
      <el-table-column label="辅导员姓名" prop="roleSort" align="center" />
      <el-table-column label="辅导员电话" prop="roleSort" align="center" />
      <el-table-column label="申请时间" prop="roleSort" align="center" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  getMyApplyHistory
} from "@/api/flowable/process";
import searchForm from "@/components/Search/searchForm.vue";

export default {
  name: "myApply",
  components: { searchForm },
  data() {
    return {
      // 遮罩层
      loading: true,
      formLabelWidth: "100px",
      formOptions: [
        {
          label: "开始时间",
          prop: "startTime",
          element: "el-date-picker",
          type: 'datetime',
          valueFormat: 'yyyy-MM-dd HH:mm:ss'
        },
        {
          label: "结束时间",
          prop: "endTime",
          element: "el-date-picker",
          type: 'datetime',
          valueFormat: 'yyyy-MM-dd HH:mm:ss'
       }
      ],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      applyList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        flowKey: '',
        name: '',
        startTime: '',
        endTime: ''
      }
    };
  },
  created() {
    if (this.$route.query.type) {
      this.queryParams.flowKey = this.$route.query.type
      this.getList();
    }
  },
  methods: {
    // 获取搜索表单提交的数据
    onSearch(val) {
      // 查询条件和分页数据合并
      const arr = Object.assign(this.queryParams, val);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置
    onReset(data) {
      console.log(data);
      this.queryParams.pageNum = 1;
      const arr = Object.assign(this.queryParams, data);
      console.log(this.queryParams);
      this.getList();
    },
    /** 查询申请记录列表列表 */
    getList() {
      this.loading = true;
      getMyApplyHistory(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.applyList = response.data.records;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    // 所有菜单节点数据
    getMenuAllCheckedKeys() {
      // 目前被选中的菜单节点
      let checkedKeys = this.$refs.menu.getCheckedKeys();
      // 半选中的菜单节点
      let halfCheckedKeys = this.$refs.menu.getHalfCheckedKeys();
      checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
      return checkedKeys;
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      if (this.$refs.menu != undefined) {
        this.$refs.menu.setCheckedKeys([]);
      }
      (this.menuExpand = false),
        (this.menuNodeAll = false),
        (this.deptExpand = true),
        (this.deptNodeAll = false),
        (this.form = {
          roleId: undefined,
          roleName: undefined,
          roleKey: undefined,
          roleSort: 0,
          status: "0",
          menuIds: [],
          deptIds: [],
          menuCheckStrictly: true,
          deptCheckStrictly: true,
          remark: undefined,
        });
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>